/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package midpmpc;

/**
 *
 * @author vvs
 */
public class PlaylistView extends FileListView{
    String currId="";
    Mpc mpc;
    public PlaylistView(Mpc parent) {
        super(parent);
        setTitle("Playlist");
        setMenuText("del", "back");
        mpc=parent;
//        super(Choice.IMPLICIT);
    }
    String formatFile(FileInfo f)
    {
        if (f.id.equals(currId))
            return '*' + f.artist + " - " + f.title;
        return f.artist + " - " + f.title;

    }
    public void setCurrId(String id)
    {
//        if (!(currId.equals(id)))
//        {
            currId=id;
//            setFiles(files);
//        }
    }
    public void keyPressed(int key)
    {
        if (key==FIRE)
        {
            //Log.warn("Selected file#"+String.valueOf(getSelected()));
            MpdConnection.sendCmd("playid "+currentId());

        }
        else if (key==MENU_LEFT)
        {
            MpdConnection.sendCmd("deleteid "+currentId());
        }
        else
        {
            super.keyPressed(key);
            return;
        }
        Mpc.updateStatus();
        update();
//        setFiles(MpdConnection.sendCmd("playlistinfo").toFileList());
//        repaint();

    }
    public void showNotify()
    {
        super.showNotify();
        setFiles(MpdConnection.sendCmd("playlistinfo").toFileList());
    }
    public void update()
    {

        Object id=Mpc.mpdInfo.get("Id");
//        if (!currId.startsWith(id))
//        {
        if (id!=null)
            currId=id.toString();
        setFiles(files);
        repaint();
//        }
    }
    public void setFiles(FileInfo[] fi)
    {
        int curr=0;
        curr=getSelected();
        super.setFiles(fi);
        if (files!=null)
        {
            if (curr>files.length-1)
                curr=files.length-1;
            setSelected(curr);
        }
    }
}
